<?php
/* @var $this CatalogController */
/* @var $model Catalog */
/* @var $form CActiveForm */
CHtml::$errorContainerTag = 'span';
?>

<div class="form" ng-app="picturesEditor">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'catalog-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableClientValidation'=>true,
	'clientOptions'=>array(
		'validateOnSubmit'=>true,
	),
	'errorMessageCssClass'=>'error'
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<div class="large-12 columns">
			<label>
		<?php echo $form->labelEx($model,'title'); ?>
		<?php echo $form->textField($model,'title',array('size'=>60,'maxlength'=>100)); ?>
		</label>
		<?php echo $form->error($model,'title'); ?>
		</div>
	</div>

	<div class="row">
		<div class="large-12 columns">
			<label>
		<?php echo $form->labelEx($model,'description'); ?>
		<?php echo $form->textArea($model,'description',array('rows'=>6, 'cols'=>50)); ?>
		</label>
		<?php echo $form->error($model,'description'); ?>
		</div>
	</div>

	<div class="row">
		<div class="large-12 columns">
			<label>
		<?php echo $form->labelEx($model,'download_url'); ?>
		<?php echo $form->textField($model,'download_url',array('size'=>60,'maxlength'=>255)); ?>
		</label>
		<?php echo $form->error($model,'download_url'); ?>
		</div>
	</div>

	<div class="row">
		<div class="large-12 columns">
		<select name="Catalog[parent]" >
			<option value="">---</option>
			<?php
			$catalogs = Catalog::model()->findAll();
			foreach ($catalogs as &$catalog) {
				if($catalog->id == $model->parent){
					$selected = 'selected';
				}else{
					$selected = '';
				}
				echo '<option '.$selected.' value="'.$catalog->id.'">'.$catalog->title.'</option>';
			}
			?>
		</select>
	</div>
	</div>

	<div class="row" ng-controller="PicturesEditorCtrl" ng-init="init('catalog-form', '<?php echo Yii::app()->createAbsoluteUrl("pictures/upload"); ?>', '<?php echo Yii::app()->request->baseUrl; ?>/', '<?php echo CHtml::encode(CJSON::encode($model->pictures)); ?>')">
		<div class="large-12 columns">
			<?php echo $form->labelEx($model,'image'); ?>
			<div class="large-3 columns button secondary [radius round]">
				Select Image
				<input class=" " type="file" name="file" id="file" on-change="uploadPicture" />
			</div>
			<div id="uploads" >
				<ul class="clearing-thumbs no-bullet" data-clearing>
					<li class="" ng-repeat="picture in pictures">
						<div class="fi-x-circle right" ng-click="deletePicture(picture)"></div>
						<a class="th" ng-href="{{picture.url}}">
							<img width="100px" ng-src="{{picture.url}}" />
							<input type="hidden" name="pictures[]" ng-value="picture.url" />
						</a>
					</li>
				</ul>
			</div>
		</div>
	</div>

	<div class="row buttons">
		<div class="large-12 columns">
			<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('class'=>'medium button [secondary radius round]')); ?>
		</div>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->


<script src="<?php echo Yii::app()->request->baseUrl; ?>/assets/js/PicturesEditorController.js"></script>